<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<style>
    .input-gray{
        background-color: #E0EEEE;
    }
</style>
<h4>数据信息
    <div class="fr">
        <c:if test="${isEdit}">
            <a href="javascript:void(0)" class="dggui-icon-btn" onclick="editForm.init(this,{form:'#dataInfo'})"><i class="iconfont icon-bianji1"></i><span>编辑</span></a>
        </c:if>
    </div>
</h4>
<form action="" id="dataInfo">
    <table class="dggui-table-info edit">
        <tbody>
        <tr>
            <th>接单时间：</th>
            <td>
                <p><fmt:formatDate value="${order.receiveOrderDate}" type="both" pattern="yyyy-MM-dd"/></p>
                <input id="receiveOrderDate" name="receiveOrderDate" type="text" class="dggui-input input-gray" readonly value="<fmt:formatDate value="${order.receiveOrderDate}" type="both" pattern="yyyy-MM-dd"/>">
            </td>
            <th>流程人员：</th>
            <td>
                <p>${order.flowUserName}</p>
                <input id="flowUserName" name="flowUserName" type="text" class="dggui-input input-gray" readonly value="${order.flowUserName}">
            </td>
            <th>产品：</th>
            <td>
                <p>${order.businessProductName}</p>
                <input id="businessProductName" name="businessProductName" type="text" class="dggui-input input-gray" readonly value="${order.businessProductName}">
            </td>
            <th>服务合同编号：</th>
            <td>
                <p>${order.contractNo}</p>
                <input id="contractNo" name="contractNo" type="text" class="dggui-input input-gray" readonly value="${order.contractNo}">
            </td>
        </tr>
        <tr>
            <th>渠道：</th>
            <td>
                <p>${order.channelName}</p>
                <input id="channelName" name="channelName" type="text" class="dggui-input input-gray" readonly value="${order.channelName}">
            </td>
            <th>支行：</th>
            <td>
                <p>${order.subBranch}</p>
                <input id="subBranch" name="subBranch" type="text" class="dggui-input" value="${order.subBranch}" maxlength="100">
            </td>
            <th>还款时间：</th>
            <td>
                <p id="loan_way_and_date_txt"></p>
                <input name="wayOfLoan" id="wayOfLoan" type="hidden" data-old="${order.wayOfLoan}"  value="${order.wayOfLoan}">
                <input name="dateOfLoan" id="dateOfLoan" type="hidden" data-old="${order.dateOfLoan}"  value="${order.dateOfLoan}">
            </td>
            <th>说明：</th>
            <td colspan="5">
                <p>${order.accountFor}</p>
                <input id="accountFor" name="accountFor" type="text" class="dggui-input" value="${order.accountFor}" style="max-width: 100%" maxlength="200">
            </td>
        </tr>
        </tbody>
    </table>
</form>
<script src="${rootUrl}/static/js/rzsc/common/files/annex2.js?v=${version}" type="text/javascript" charset="utf-8"></script>
<script>
    var dggdate;
    dggui.use(['dggdate'],function () {
        $("#loan_way_and_date_txt").text(joinLoanWayAndTimeTxt('${order.wayOfLoan}','${order.dateOfLoan}'));
        dggdate = dggui.dggdate;
    });

    var editForm={
        options:{
            form:'',
            saveFun:function () {

            },
            cancleFun:function () {

            }
        },
        init:function (obj,opt) {
            opt=this.options=$.extend({},this.options,opt);
            var btnHtm='<div id="'+this.options.form+'-btn"><a href="javascript:void(0)" class="dggui-btn dggui-btn-sm" onclick="editForm.saveForm(this)">保存</a><a href="javascript:void(0)" class="dggui-btn dggui-btn-primary dggui-btn-sm" onclick="editForm.cancleForm(this)">取消</a></div>'
            $(obj).before(btnHtm);
            $(obj).hide()
            this.dataVal(opt)
        },
        dataVal:function (opt) {
            $(opt.form).find('.edit').addClass('be-editing');
            $.each($(opt.form)[0],function (i,v) {
                var formtype=$(v)[0].type;
                if(formtype=='radio'||formtype=='checkbox') {
                    $(v).parents('td').children('p').hide();
                    $(v).parents('td').show();
                }else {
                    if($(v)[0].id == 'wayOfLoan' || $(v)[0].id == 'dateOfLoan'){
                        $("#loan_way_and_date_txt").val(joinLoanWayAndTime($("#wayOfLoan").val(),$("#dateOfLoan").val()));
                        $("#loan_way_and_date_txt").html(joinLoanWayAndTime('${order.wayOfLoan}','${order.dateOfLoan}'));
                    }else if($(v)[0].id == 'thirdpartyName' || $(v)[0].id == 'thirdpartyNumber') {
                        $("#thirdparty_name_and_number").html(joinThirdparty('${order.thirdpartyName}','${order.thirdpartyNumber}'));
                    }else{
                        $(v).parents('td').children('p').hide();
                        $(v).parents('td').children('div').show();
                        $(v).show();
                    }
                }
            })
        },
        saveForm:function (obj,id) {
            var flag = saveData();
            if(!flag)
                return false;
            var opt=this.options;
            opt.saveFun(opt);
            $(opt.form).find('.edit').removeClass('be-editing');
            $.each($(opt.form)[0],function (i,v) {
                var formtype=$(v)[0].type;
                if(formtype=='radio'||formtype=='checkbox') {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').hide();
                }else if(formtype=='file'){
                    return false;
                }else{
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').children('div').hide();
                    $(v).hide();
                }
            });
            $(obj).parent().next().show();
            $(obj).parent().remove();
        },
        cancleForm:function (obj) {
            var opt=this.options;
            opt.cancleFun(opt);
            $(opt.form).find('.edit').removeClass('be-editing');
            $.each($(opt.form)[0],function (i,v) {
                var formtype=$(v)[0].type;
                if(formtype=='radio'||formtype=='checkbox') {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').hide();
                }else if($(v)[0].id == 'wayOfLoan' || $(v)[0].id == 'dateOfLoan'){
                    $("#loan_way_and_date_txt").text(joinLoanWayAndTimeTxt($("#wayOfLoan").attr("data-old"),$("#dateOfLoan").attr("data-old")));
                }else if($(v)[0].id == 'thirdpartyName' || $(v)[0].id == 'thirdpartyNumber') {
                    $("#thirdparty_name_and_number").text('${order.thirdpartyName}'+"/"+'${order.thirdpartyNumber}');
                }else if(formtype=='file'){
                    return false;
                }else {
                    $(v).parents('td').children('p').show();
                    $(v).parents('td').children('div').hide();
                    $(v).hide();
                }
            });
            $(obj).parent().next().show();
            $(obj).parent().remove();
        }
    }
    //保存
    function saveData(){
        var params = serializeObject($("#dataInfo"));
        params.id = '${order.id}';
        dggui.dialog.loading();
        $.post(sysInfo.basePath+"/order_detail/order_info_save.do",{orderStr:JSON.stringify(params)},function(result){
            dggui.dialog.loading('close');
            if(result.code == 0){
                dggui.dialog.succeed('保存成功！');
                loadProductData();
            }else{
                dggui.dialog.errors(result.msg);
            }

        })
    }
</script>